package com.lx.util.secure.algorithm.coder;

import com.lx.entity.Var;
import com.lx.util.LX;

import java.util.Map;

public class Encoder {

    private byte[] data;

    public Encoder(byte[] data) {
        this.data = data;
    }

    public byte[] getBytes(){
        return data;
    }

    public String getString(){
        return new String(data);
    }

    public String getString(Character character){
        return new String(data, character);
    }

    public String getBase64String(){
        return Base64.getCoder().encodeToString(data);
    }

    public String getHexString(){
        return Hex.getCoder().encodeToString(data);
    }

    public String getUrlString(){
        return Url.getCoder().encodeToString(new String(data));
    }

    public <T>T getObj(Class<? extends T> cls){
        return LX.toObj(cls, getString());
    }

    public Var getMap(){
        return LX.toMap(getString());
    }

    @Override
    public String toString() {
        return getString();
    }
}
